/* 
 * File:   sceneobject.cpp
 * Author: Satan
 * 
 * Created on September 9, 2012, 9:24 PM
 */

#include "hfgl/hfgl_point.h"
#include "sceneobject/sceneobject.h"
#include "hfgl/hfgl_picture.h"
#include "engine.h"

#include <windows.h>
#include <GL/glut.h> 

sceneobject::sceneobject() 
{
    m_image = NULL;
}

sceneobject::sceneobject(const sceneobject& orig) 
{
}

sceneobject::~sceneobject() 
{
}

void sceneobject::setImage(svgloader* image)
{
    m_image = image;
    m_picture = m_image->getPicture();
}

void sceneobject::draw()
{
    glColor3f(1.0,1.0,1.0);
    
    if (m_picture)
    {
        hfgl_picture *picture = m_picture;
        
        for(int ic = 0; ic < picture->getArrayCount(); ic++)
        {
            DEBUG_OUT("ic=" << ic);
            hfgl_surface *surface = picture->getSurface(ic);
            for (int i = 0; i < surface->getCountPolygons(); i++)
            {
                DEBUG_OUT("\ti=" << i);
                hfgl_polygon *polygon = surface->getPolygons()[i];
                glColor3fv(polygon->color);

                glBegin(polygon->mode);
                for (int  n = 0; n < polygon->array_y; n++)
                    glVertex2fv(polygon->getCoordinate(n));
                glEnd();
            };
        };
    };
}